package com.sumainfor.pc.market.controller;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.market.service.TcmktCorporateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 企业客户
 * <p>
 *
 * @author: zhoucong
 * @create: 2019-05-29 20:09
 **/
@Controller
@RequestMapping("/Corporate")
public class TcmktCorporateController {



    @Autowired
    TcmktCorporateService tcmktCorporateService;

    /**
    * <p>
    * 增加企业客户
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @ResponseBody
    @PostMapping("/addCorporate")
    public JsonResult addCorporate(@RequestBody Map<String,Object> params){
        return tcmktCorporateService.addCorporate(params);
    }


    /**
     * <p>
     * 查询企业客户列表
     * </p>
     *
     * @author: zhoucong
     * @since:
     */
    @ResponseBody
    @PostMapping("/getCorporateList")
    public JsonResult getCorporateList(@RequestBody Map<String,Object> params,Pager pager) {

        JsonResult result = new JsonResult();

        pager.setPageno((Integer) params.get("pageno"));
        pager.setPagesize((Integer) params.get("pagesize"));
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();

        Integer cout = tcmktCorporateService.getCorporateCount(params);
        if (cout == 0) {
            return pageUtils.getJsonResult(new ArrayList<Map<String, Object>>(), params, cout);
        } else {

            List<Map<String, Object>> getCorporateList = tcmktCorporateService.getCorporateList(params);
            return pageUtils.getJsonResult(getCorporateList, params, cout);
        }

    }



    /**
     * <p>
     * 查询企业下的房源详情
     * </p>
     *
     * @author: zhoucong
     * @since:
     */
    @ResponseBody
    @PostMapping("/getCorHouList")
    public JsonResult getCorHouList(@RequestBody Map<String,Object> params,Pager pager) {

        JsonResult result = new JsonResult();
        pager.setPageno((Integer) params.get("pageno"));
        pager.setPagesize((Integer) params.get("pagesize"));
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();

        Integer cout = tcmktCorporateService.getCorHouCount(params);
        if (cout == 0) {
            return pageUtils.getJsonResult(new ArrayList<Map<String, Object>>(), params, cout);
        } else {

            List<Map<String, Object>> getCorporateList = tcmktCorporateService.getCorHouList(params);
            return pageUtils.getJsonResult(getCorporateList, params, cout);
        }

    }





}
